package Shopcar;

import java.util.ArrayList;
import java.util.Scanner;

public class CommodityOp {
    ArrayList<Commodity> cm = new ArrayList<>();

    public CommodityOp(ArrayList<Commodity> cm) {
        this.cm = cm;
    }

    Scanner sc = new Scanner(System.in);


    public void delete() {
        double sum = 0;
        System.out.println("请输入想删除的商品序号：");
        int num = sc.nextInt();
        cm.remove(num - 1);
        System.out.println("删除成功！");

        for (int i = 0; i < cm.size(); i++) {
            cm.get(i).String();
            sum += cm.get(i).getPrice();
        }
        System.out.println("总价格：" + sum);
    }

    public void add() {
        double sum = 0;
        System.out.println("请输入想添加的商品以及其信息：");
        Commodity cm1 = new Commodity();
        System.out.println("请输入商品名：");
        String name = sc.next();
        cm1.setName(name);
        System.out.println("请输入商品价格：");
        double a = sc.nextDouble();
        cm1.setPrice(a);
        System.out.println("请输入商品描述：");
        String c = sc.next();
        cm1.setAboutCommodity(c);
        System.out.println("请输入商品数量：");
        int d = sc.nextInt();
        cm1.setSum(d);
        System.out.println("添加成功！");
        cm.add(cm1);
        for (int i = 0; i < cm.size(); i++) {
            cm.get(i).String();
            sum += cm.get(i).getPrice();
        }
        System.out.println("总价格：" + sum);

    }
}
